package com.hdaccp.lettingboot.conf;

import com.hdaccp.lettingboot.servlet.LettingFilter;
import com.hdaccp.lettingboot.servlet.LettingListener;
import com.hdaccp.lettingboot.servlet.UserServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * spring-serverconfig.xml
 * <bean id = "getServletRegistrationBean" class=""ServletRegistrationBean>
 *
 * </bean>
 *
 * <bean id="" class>
 *
 * </bean>
 *
 * <bean>
 *
 * </bean>
 */
@Configuration
public class ServletConfig {

    @Bean
    public ServletRegistrationBean getServletRegistrationBean(){
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean() ;
        servletRegistrationBean.setServlet(new UserServlet());
        servletRegistrationBean.addUrlMappings("/userServlet");
        return servletRegistrationBean ;
    }

    @Bean
    public FilterRegistrationBean getFilterRegistrationBean(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean() ;
        filterRegistrationBean.setFilter(new LettingFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean ;
    }
    @Bean
    public ServletListenerRegistrationBean getServletListenerRegistrationBean(){
        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean() ;
        servletListenerRegistrationBean.setListener(new LettingListener());
        return servletListenerRegistrationBean ;
    }
}
